package com.tbs.lock.config;

import com.tbs.common.util.base.BeanUtil;
import com.tbs.lock.ILockProvider;
import com.tbs.lock.impls.providers.JdkLockProvider;
import com.tbs.lock.util.LockUtil;
import org.springframework.context.annotation.Bean;

import javax.annotation.Resource;

public class LockConfig {
    @Resource
    private LockProperty lockProperty;

    /**
     * 锁提供者
     */
    @Bean
    ILockProvider lockProvider() {
        return BeanUtil.buildBeanFromProperties(() -> {
            return new JdkLockProvider();
        }, lockProperty.getLockProviderType(), BeanUtil::buildByEmptyArgs);
    }

    @Bean
    LockUtil lockUtil() {
        return new LockUtil();
    }
}
